package com.java1412.web.controller.admin;

import com.auth0.jwt.exceptions.AlgorithmMismatchException;
import com.auth0.jwt.exceptions.SignatureVerificationException;
import com.auth0.jwt.exceptions.TokenExpiredException;
import com.auth0.jwt.interfaces.DecodedJWT;
import com.java1412.common.dto.UserDto;
import com.java1412.common.utils.R;
import com.java1412.common.utils.ResponseEnum;
import com.java1412.web.service.UserService;
import com.java1412.web.utils.JWTUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author java1412
 * @since 2025-05-20 11:19
 */
@RestController
@RequestMapping(value = "/admin/user")
// @CrossOrigin // 如果请求头中含有其他的请求头，这个注解没有用，要使用过滤器来控制允许跨域
@Api(tags = "后台用户接口")
public class AdminUserController {
    @Resource
    private UserService userService;

    @PostMapping(value = "/login")
    @ApiOperation(value = "登录")
    public R login(
            // @RequestBody——表示前端提交的数据是json形式
            @RequestBody UserDto userDto) {
        System.out.println(userDto);
        // 调用service完成登录
        R r = userService.adminLogin(userDto);
        return r;
    }

    @Resource
    private JWTUtil jwtUtil;

    //    @GetMapping(value = "/test")
//    @ApiOperation(value = "测试token")
//    public R test(
//            @RequestParam(value = "token") String token
//    ) {
//        return R.r(ResponseEnum.JWT_VERIFY_SUCCESS);
//    }
    @GetMapping(value = "/test")
    @ApiOperation(value = "测试token")
    public R test() {
        return R.r(ResponseEnum.JWT_VERIFY_SUCCESS);
    }

    @GetMapping
    @ApiOperation(value = "获取用户信息")
    public R list(UserDto userDto) {
        R r = userService.find(userDto);
        return r;
    }
}
